package com.daodaofun.weibo.controller;

import com.daodaofun.util.CommonCode;
import com.daodaofun.weibo.model.Post;
import com.daodaofun.weibo.model.User;
import com.daodaofun.weibo.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
@RequestMapping("p")
public class PostController {

    @Autowired
    private PostService postService;

    @PostMapping("post")
    @ResponseBody
    public Integer post(@RequestBody  Post post, HttpSession session){
        System.out.println(post.getContent());
        User user = (User) session.getAttribute("user");
        post.setUserId(user.getId());
        postService.save(post);
        return CommonCode.SUCCESS;
    }
}
